package com.xxxy.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author sjh
 * @date 2022/2/27 15:46
 */
@Data
@TableName("es_examination_paper")
public class ExaminationPaper implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "试卷id")
    private Integer id;

    @ApiModelProperty(value = "试卷简介")
    private String content;

    @ApiModelProperty(value = "课程id")
    private Integer course_id;

    @ApiModelProperty(value = "试卷创建者账号")
    private String creator;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "试卷创建时间")
    private Date createTime;

    @ApiModelProperty(value = "难度系数")
    private BigDecimal difficulty;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "考试时间")
    private Date examTime;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "考试结束时间")
    private Date endTime;

    @ApiModelProperty(value = "审核人账号")
    private String reviewer;

    @ApiModelProperty(value = "是否审核通过")
    private Integer approve;

    @TableField(exist = false)
    @ApiModelProperty(value = "满分分数")
    private Double score;

    @ApiModelProperty(value = "试卷状态(1=待组卷，2=待审卷，3=待开始，4=进行中，5=批阅中，6=已结束)")
    private Integer status;

    @ApiModelProperty(value = "试题")
    private String questions;

    @ApiModelProperty(value = "小节分布")
    private String section;

    @ApiModelProperty(value = "小节分数")
    private String sectionScore;

    @ApiModelProperty(value = "知识点")
    private String points;

    @ApiModelProperty(value = "是否被设置为定时任务")
    private Integer timing;

    public Double getScore() {
        int i = 1;
        score = 0.0;
        String[] section = this.section.split(",");
        String[] section_score = this.sectionScore.split(",");
        while (i <= section.length){
            if(i == 1){
                score = score + (Integer.parseInt(section[i-1]))* Double.parseDouble(section_score[i-1]);
            }
            else {
                score = score + (Integer.parseInt(section[i-1]) - Integer.parseInt(section[i-2]))* Double.parseDouble(section_score[i-1]);
            }
            i++ ;
        }
        return score;
    }
}
